﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text;

namespace WindowsFormsApplication1
{
    class DriveButton: Button
    {
        private string fileLink;
        private bool isDriveAttached;

        public DriveButton(string dl)
        {
            BackgroundImage = WindowsFormsApplication1.Properties.Resources.bgrnd128;
            Image = WindowsFormsApplication1.Properties.Resources.emptyspace;
            FlatStyle = System.Windows.Forms.FlatStyle.Popup;
            Font = new System.Drawing.Font("Arial", 8.25F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(204)));
            Size = new System.Drawing.Size(128, 128);
            TextAlign = System.Drawing.ContentAlignment.BottomCenter;

            Text = dl;
            isDriveAttached = false;
        }

        public void AttachVD(string fl)
        {
            if (!isDriveAttached)
            {
                fileLink = fl;
                string lbl = System.IO.Path.GetFileNameWithoutExtension(fl);
                Image = WindowsFormsApplication1.Properties.Resources.filledspace;

                System.IO.DriveInfo d = new System.IO.DriveInfo(Text);
                if (d.IsReady) d.VolumeLabel = lbl;

                string tmp = Text + Environment.NewLine + lbl;
                Text = tmp;                
                isDriveAttached = true;
            }
        }

        public void DetachVD()
        {
            if (isDriveAttached)
            {
                Image = WindowsFormsApplication1.Properties.Resources.emptyspace;
                string tmp = Text.Substring(0, 3);
                Text = tmp;
                isDriveAttached = false;
            }
        }

        public bool IsDriveAttached
        {
            get { return isDriveAttached; }
        }
    }
}
